package com.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.filter.GenericFilterBean;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author CHL
 * @ClassName: Utf8EncodingFilter
 * @Description: 默认使用utf-8字符集
 * @date 2022/8/5 16:24
 * @Version 1.0
 */
public class Utf8EncodingFilter extends GenericFilterBean {
    private static Logger logger = LoggerFactory.getLogger(Utf8EncodingFilter.class);
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        Utf8EncodingRequest request =new Utf8EncodingRequest((HttpServletRequest)servletRequest);
        filterChain.doFilter(request,servletResponse);
    }

    protected void initFilterBean() throws ServletException {
        logger.info("---加载Utf8EncodingFilter！---");
    }
}
